﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace RFW.Weather.Forecast
{
	public class Date
	{
		public long EPOCH { get; set; }
		public string PrettyShort { get; set; }
		public string Pretty { get; set; }
		public short Day { get; set; }
		public short Month { get; set; }
		public short Year { get; set; }
		public short DayOfYear { get; set; }
		public short Hour { get; set; }
		public short Minute { get; set; }
		public short Second { get; set; }
		public string MonthName { get; set; }
		public string WeekDay { get; set; }
		public string TimeZoneShort { get; set; }
		public string TimeZone{get; set; }

		public DateTime DateTime
		{
			get { return new DateTime(this.Year, this.Month, this.Day, this.Hour, this.Minute, this.Second); }
		}

		public DateTime UTCDateTime
		{
			get { return new DateTime(1970, 1, 1).AddSeconds(this.EPOCH); }
		}

		public override string ToString()
		{
			return this.Pretty;
		}

		public static Date Linq(XElement element)
		{
			Date date = new Date();
			date.EPOCH = Convert.ToInt32(element.Element("epoch").Value);
			date.PrettyShort = element.Element("pretty_short").Value;
			date.Pretty = element.Element("pretty").Value;
			date.Day = Convert.ToInt16(element.Element("day").Value);
			date.Month = Convert.ToInt16(element.Element("month").Value);
			date.Year = Convert.ToInt16(element.Element("year").Value);
			date.DayOfYear = Convert.ToInt16(element.Element("yday").Value);
			date.Hour = Convert.ToInt16(element.Element("hour").Value);
			date.Minute = Convert.ToInt16(element.Element("min").Value);
			date.Second = Convert.ToInt16(element.Element("sec").Value);
			date.MonthName = element.Element("monthname").Value;
			date.WeekDay = element.Element("weekday").Value;
			date.TimeZoneShort = element.Element("tz_long").Value;
			date.TimeZone = element.Element("tz_long").Value;

			return date;
		}
	}
}
